<?php

define('IN_PHPBB', true);
$phpbb_root_path = './../';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include('login.php');

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_ALI);
init_userprefs($userdata);

	//
	// Start output of page
	//
	
	define('SHOW_ONLINE', true);
	$page_title = 'Confirmaciones';
	
if($_POST){
	$ids=explode("#",$_POST['ids_jugadores']);
	foreach($ids as $id){
	$sql = 'UPDATE ' . USERS_TABLE . ' SET corre="'.$_POST['corre'.$id].'" WHERE user_id="'.$id.'"';
	
	if ( !($result = $db->sql_query($sql)) )
		{	
		message_die(GENERAL_ERROR, 'Could not obtain user and group information', '', __LINE__, __FILE__, $sql);
		}	
	}
}	
	$sql = "SELECT t1.user_id, t1.username, t1.user_teamcolour, t1.user_rango, t1.manager, t1.rookie, t1.m_nopilot, t1.corre, t1.primer_temp, t2.rango_id, t3.idteam, t3.team, t3.teamcolour
		FROM " . USERS_TABLE . " t1, phpbb_rangos t2, phpbb_equipos t3
		WHERE t1.user_teamcolour <> '#000000' AND t1.user_rango=t2.rango_id AND t1.user_teamcolour=t3.teamcolour
		ORDER BY t3.teamcolour ASC, t1.user_teamcolour DESC, t1.user_rango ASC";
	
	
	//$sql = "SELECT t1.user_id, t1.username, t1.user_colour, t1.user_rango, t1.manager, t1.rookie, t1.m_nopilot, t1.primer_temp, t2.rango_id, t1.corre, t3.group_id, t3.group_name, t3.group_colour, t3.group_position
	//	FROM " . USERS_TABLE . " t1, phpbb_rangos t2, " . GROUPS_TABLE . " t3
	//	WHERE t1.user_colour <> '#000000' AND t1.user_rango=t2.rango_id AND t1.user_colour=t3.group_colour AND t1.m_nopilot != 'si'
	//	ORDER BY t3.group_position ASC, t1.user_colour DESC, t1.user_rango ASC";

if( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Could not query users', '', __LINE__, __FILE__, $sql);
}

echo '<div class="subfondoB">
 	<div class="titulo">
    	<p>'.$lang['Teams'].'</p>
    </div>
    <div class="cont">
    	<div class="dentro" style="text-align: center;">

	  <table>
		<tr>
			<td align="center" style="background-color: #ffffff; padding:12px 7px 20px 7px;">
				<table align="center">';
				

	$c=1;
	$columnas=3;
	
	$equipo_anterior='';
	$ids_jugadores='';
	while($row = $db->sql_fetchrow($result) ){
	$ids_jugadores.=$row["user_id"]."#";
		switch ($row["rango_id"]){ 
    		case 1: 
        		$rangoidioma = $lang['Poficial']; 
       			break; 
    		case 2: 
       			$rangoidioma = $lang['Soficial']; 
        		break; 
			case 3: 
       			$rangoidioma = $lang['Toficial']; 
        		break;
			case 4: 
       			$rangoidioma = $lang['Preserv']; 
        		break; 
			case 5: 
       			$rangoidioma = $lang['Sreserv']; 
        		break;
			case 6: 
       			$rangoidioma = $lang['Treserv']; 
        		break;
    		default: 
        		$rangoidioma = $lang['Norank'];
				break;
		} 
				   
				   
			
	
			
		if($row["user_teamcolour"] <> $equipo_anterior){
			if($c!=1) echo '</table>';
			if($c>$columnas){
				$c=1;
				echo '</td></tr>';
			}
			if($c==1) echo '<tr><td valign="top">';
			else echo '</td><td valign="top">';
			$c++;
			$equipo_anterior = $row["user_teamcolour"];
			
			echo '<table>
				  	<tr>
						<td colspan="2" align="center"><img src="./../cabeceras/png.php?texto='.$row["team"].'&color='.substr($row["teamcolour"], 1).'" border="0"></td>
					</tr>';
			
		}
		echo '<tr>
			  	<td class="rowuser" style="border-bottom: 1px solid '.$row["user_teamcolour"].'; border-right: 1px solid '.$row["user_teamcolour"].';">
					<div style="float: left;">'.$row["username"].'</div>
					<div style="float: right;">'.$iconmg.''.$iconrk.''.$icon1a.'</div></td>
				<td class="rowrng" style="border-bottom: 1px solid '.$row["user_teamcolour"].'; border-right: 1px solid '.$row["user_teamcolour"].';">
					<span class="genbigb">'.$rangoidioma.'</span>
					
					
				</td>';
			  	echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
				
			  	echo '<td align="center">';
				   if($row['corre']=="si") $checked='checked="checked"';
				   else $checked='';
				echo '<input name="corre'.$row['user_id'].'" type="checkbox" value="si" '.$checked.'></td>
				   <td align="center">
			</tr>';	  
			//
			// Se le da valor vacio a icon mg para que cuando haga el if no se quede el valor.
			//
				  
			$iconmg = '';
			$iconrk = '';
			$icon1a = '';
	}
	echo '</table>';
	while($c<$columnas){
		echo '</td><td>';
		$c++;
	}
		echo '<input type="hidden" name="ids_jugadores" value="'.substr($ids_jugadores, 0, -1).'">
			<tr> 
				<td class="catHead" colspan="7" height="20" align="center"><input type="submit" name="submit" value="Enviar"></td>
	  		</tr>
	  
	  </form>';
	echo'</td></tr></table></td></tr></table></div></div>';

//
// Generate the page
//

include('cerrar.php');

?>